package com.wei.jpush.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.wei.jpush.DetailActivity;

import cn.jpush.android.api.JPushInterface;

/**
 * @author zhangwei
 * @version V1.0
 * @Title: Advanced
 * @Package com.wei.jpush.revciver
 * @Description:
 * @date 15/10/26 上午11:10
 */

public class JpushReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent != null && intent.getAction() != null) {
            if (intent.getAction().equals(JPushInterface.ACTION_REGISTRATION_ID)) {
                //获得设置在极光推送的账号id
                String id = intent.getExtras().getString(JPushInterface.EXTRA_REGISTRATION_ID);
            } else if (intent.getAction().equals(JPushInterface.ACTION_MESSAGE_RECEIVED)) {
                //获得自定的通知
                String msgId = intent.getExtras().getString(JPushInterface.EXTRA_MSG_ID);
                String content = intent.getExtras().getString(JPushInterface.EXTRA_MESSAGE);
                String extra = intent.getExtras().getString(JPushInterface.EXTRA_EXTRA);
                Log.e("ACTION_MESSAGE_RECEIVED", msgId);
                Log.e("ACTION_MESSAGE_RECEIVED", content);
                Log.e("ACTION_MESSAGE_RECEIVED", extra);
            } else if (intent.getAction().equals(JPushInterface.ACTION_NOTIFICATION_RECEIVED)) {
                //获得发送的通知的消息
                String msgId = intent.getExtras().getString(JPushInterface.EXTRA_MSG_ID);
                String title = intent.getExtras().getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
                String content = intent.getExtras().getString(JPushInterface.EXTRA_ALERT);
                String extras = intent.getExtras().getString(JPushInterface.EXTRA_EXTRA);
                Log.e("ACTION_MESSAGE_RECEIVED", msgId);
                Log.e("ACTION_MESSAGE_RECEIVED", content);
                Log.e("ACTION_MESSAGE_RECEIVED", title);
                Log.e("ACTION_MESSAGE_RECEIVED", extras);
            //是通知栏的消息被点击
            } else if (intent.getAction().equals(JPushInterface.ACTION_NOTIFICATION_OPENED)) {
                String msgId = intent.getExtras().getString(JPushInterface.EXTRA_MSG_ID);
                String title = intent.getExtras().getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
                String content = intent.getExtras().getString(JPushInterface.EXTRA_ALERT);
                Intent stipIntent = new Intent(context, DetailActivity.class);

                stipIntent.putExtra("msgId", msgId);
                stipIntent.putExtra("content", content);
                stipIntent.putExtra("title", title);
                stipIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(stipIntent);


            }


        }


    }
}
